<template>
<div>
    <AutoQuery ref="auto-query" :query="query" :page="page"></AutoQuery>
    <Tabs type="line">
        <TabPane label="普通用户登录日志">
            <AutoTable :columns="columns1" :data="loglist" :page="page"></AutoTable>
        </TabPane>
        <TabPane label="地区登录次数排序">
            <AutoTable :columns="district_user" :data="district_data" :page="pageIp"></AutoTable>
        </TabPane>
        <TabPane label="用户登录次数排序">
            <AutoTable :columns="times_user" :data="user_data" :page="pageUser"></AutoTable>
        </TabPane>
    </Tabs>
</div>
</template>

<script>
import Page from "@/common/model/Page";
import AutoTable from "@/common/components/AutoTable";
import AutoQuery from "@/common/components/AutoQuery";
import parent from "../Parent"
export default {
    extends:parent,
    components: {
        AutoTable,AutoQuery
    },
    home:'name',
    data () {
        var formItem = {
            role_type:'0',
            id:'',
            operation_type: '0',     
            begin_time: '',
            end_time: ''
        };
        return {
            page: new Page("search/log", this.formatItem(formItem)),
            pageIp: new Page("search/ip_location_user"),
            pageUser: new Page("search/user_login_times"),
            formItem: formItem,
            query: { // 查询条件
                id: { type: "input", label: "用户ID：",placeholder: "请输入用户ID" },
                role_type: { type: "select", label: "用户类别：", default: "0", placeholder: "请选择用户类别", options: [
                        { value: "0", label: "不限" },
                        { value: "1", label: "游客" },
                        { value: "3", label: "个人" },
                        { value: "4", label: "企业" },
                        { value: "5", label: "服务机构" },
                ] },
                operation_type: { type: "select", label: "操作类别：", default: "0", placeholder: "请选择操作类别", options: [
                        { value: "0", label:  "所有操作" },
                        { value: "11", label: "增加" },
                        { value: "12", label: "删除" },
                        { value: "13", label: "修改" },
                        { value: "14", label: "查看" },
                        { value: "15", label: "审核" },
                        { value: "16", label: "导入" },
                        { value: "17", label: "导出" },
                        { value: "18", label: "上传" },
                        { value: "41", label: "找回密码" },
                        { value: "42", label: "注册" },
                        { value: "23", label: "下载" },
                        { value: "32", label: "登陆" },
                ] },
                begin_time: { type: "date", label: "日期", placeholder: "选择开始时间" },
                end_time: { type: "date", placeholder: "选择截止时间", handleValue: value => { return value + 24*60*60*1000 } },
            },
            columns1: [
                {
                    title: '用户身份',render:(h,params) =>{
                        var role_type =({
                            '1':"游客",
                            '3':"个人",
                            '4':"企业",
                            '5':"服务机构"
                        })[params.row.role_type];
                        return h('div', role_type);
                    }
                },
                {
                    title: '用户ID',
                    key: 'user_id'
                },
                {
                    title: '用户名',
                    key: 'username'
                },               
                {
                    title: '操作类型',render: (h, params) => {        
                        var operation = ({  
                            '11': "添加",
                            '12': "删除",
                            '13': "修改",
                            '14': "查看",
                            '15': "审核",
                            '16': "导入",
                            '17': "导出",
                            '18': "上传",
                            '19': "设为公开",
                            '23': "下载",
                            '32': "登陆",
                            '41': "找回密码",
                            '42': "注册",
                        })[params.row.operation];
                        return h('div', operation);
                    }
                },
                {
                    title: '操作描述',
                    key: 'description'
                },
                {
                    title: 'IP',
                    key: 'ip'
                },
                {
                    title: 'IP位置',
                    key: 'ip_location'
                },
                {
                    title: '操作时间',width:130,
                    sortType:'desc', 
                    sortable: true,
                    key: 'create_time',
                    render: (h, params) => {
                        return h('div', new Date(parseInt(params.row.create_time)).toLocaleDateString()+" "+new Date(parseInt(params.row.create_time)).getHours()+":"+new Date(parseInt(params.row.create_time)).getMinutes());
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    render: (h, params) => {
                        return h('div', [                            
                                h('Button',{
                                props:{
                                    type:'warning',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '5px',display:this.showButton("112213")
                                },
                                on:{
                                    click: () =>{
                                        this.delete(params.index)
                                    }
                                }
                            },'删除')
                        ]);
                    }
                }
            ],
            district_user: [
                {
                    title: 'IP位置',
                    key: 'ip_location'
                },
                {
                    title: '登录次数',
                    key: 'times',
                    sortable: true
                }
            ],
            times_user: [
                {
                    title:'用户名',
                    key: 'username'
                },
                {
                    title: '登录次数',
                    key: 'times',
                    sortable: true
                }
            ]
        }
    },
    computed: {
        district_data(){
            return this.pageIp.list
        },
        user_data(){
            return this.pageUser.list
        },
        loglist(){
            return this.page.list;
        }
    },
    methods: {
        formatItem(data) {                      
            return {
                role_type:data.role_type == "" ? 0:data.role_type,
                id: data.id == "" ? 0 : data.id,
                operation_type: data.operation_type == "" ? 0 :data.operation_type,     
                begin_time: data.begin_time==""? "":Date.parse(new Date(data.begin_time)),
                end_time: data.end_time==""? "":Date.parse(new Date(data.end_time))
            }
        },
        delete (index){
             this.$Modal.confirm({
                    title: '确认删除？',
                    content: '<p>继续删除，请点击确定按钮</p><br><p>取消，请点击取消按钮</p>',
                    onOk: () => {
                        this.api.post("feedback/delate_log",{ id: this.loglist[index].id}, res =>{
                            this.$CustomMessage.success('删除成功!');
                            this.page.getData();
                        })
                    },
                    onCancel: () => {
                        this.$CustomMessage.info('取消删除');
                    }
            });   
        }
    }
}
</script>


<style>
</style>
